"""
    HTTP请求响应示例
"""
from socket import *

sock = socket()
sock.bind(("0.0.0.0",2888))
sock.listen(5)
#等待浏览器链接
while True:
    connfd,addr = sock.accept()
    print(f"Connect from {addr}")
    #接受HTTP请求
    data = connfd.recv(1024)
    print(data.decode())

    #发送响应
    response = """HTTP/1.1 200 OK
Content-Type:text/html

Hello World!
"""
    connfd.send(response.encode())

    connfd.close()

sock.close()